package com.yld.car.market;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.yld.car.application.MyApplication;
import com.yld.car.common.ConstantUtils;
import com.yld.car.common.NetworkProgressUtils;
import com.yld.car.common.UploadImageTask;
import com.yld.car.domain.BaseColorInfo;
import com.yld.car.domain.DetailInfoCar;
import com.yld.car.domain.EditCarInfo;
import com.yld.car.domain.UserInfo;

public class MyCarUpdatePublishActivity extends BaseActivity implements
		OnItemClickListener {

	private ListView list1;
	private ListView list2;
	private ListView list3;
	private MyApplication app;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.publish_car);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
		app = this.mApp;
		this.list1 = ((ListView) findViewById(R.id.list1));
		this.list1.setOnItemClickListener(this);

		this.list2 = ((ListView) findViewById(R.id.list2));
		this.list2.setOnItemClickListener(this);

		this.list3 = ((ListView) findViewById(R.id.list3));
		this.list3.setOnItemClickListener(this);

		Intent intent = getIntent();

		if (intent != null) {
			// isEditor = intent.getBooleanExtra("isEditor", false);
			// mDetailInfoCar = (DetailInfoCar) intent
			// .getSerializableExtra("detailInfo");
			this.carType = intent.getStringExtra("carType");
			this.mname = intent.getStringExtra("carSeries");
			this.price = intent.getStringExtra("price");
		}
		TextView localTextView = (TextView) findViewById(R.id.title);

		localTextView.setText("编辑车源");

		// leftButton=(Button) findViewById(R.id.leftButton);
		showButton();

		rightButton = (Button) findViewById(R.id.rightButton);

		this.rightButton.setVisibility(View.VISIBLE);
		this.rightButton.setText("完成");
		this.rightButton.setOnClickListener(completeListener);

	}

	// 是否为编辑状态
	private boolean isEditor;
	private String id;
	// 获取当前编辑车源的详细信息
	private DetailInfoCar mDetailInfoCar;
	private Button rightButton;

	private List<Map<String, String>> allInputItems;
	// private List<Map<String, String>> allInputItems2;
	// private List<Map<String, String>> allInputItems3;
	private Map<String, String> map;

	private String color = "";
	private String insideColor = "";
	private String woodColor = "";
	private String lunGu = "";
	private String paiLiang = "";
	private String carType = "";
	private String price;
	private String carState;
	private String vin="";

	private void initViews() {
		allInputItems = new ArrayList<Map<String, String>>();

		this.map = new HashMap<String, String>();
		this.map.put("id", "typeAndStatus");
		this.map.put("title", "选择车源类型");
		this.map.put("content", this.carType);
		this.allInputItems.add(map);
		this.map = new HashMap<String, String>();
		this.map.put("id", "model");
		this.map.put("title", "选择对应系列");
		this.map.put("content", this.mname);

		this.allInputItems.add(map);

		// 添加车源状态选项

		this.map = new HashMap<String, String>();
		this.map.put("id", "carState");
		this.map.put("title", "选择车源状态");
		this.map.put("content", this.carState);
		this.allInputItems.add(map);

		this.map = new HashMap<String, String>();
		this.map.put("id", "priceInput");
		this.map.put("title", "请输入价格");
		this.map.put("content", this.price);

		this.allInputItems.add(map);

		// 添加一项车架号
		this.map = new HashMap<String, String>();
		this.map.put("id", "vin");
		this.map.put("title", "请输入车架号");
		this.map.put("content", this.vin);
		this.allInputItems.add(map);

		map = new HashMap<String, String>();
		this.map.put("id", "color");
		this.map.put("title", "请选择外观颜色");
		this.map.put("content", this.color);
		this.allInputItems.add(this.map);

		this.map = new HashMap<String, String>();
		this.map.put("id", "insideColor");
		this.map.put("title", "请选择内饰颜色");
		this.map.put("content", this.insideColor);
		this.allInputItems.add(this.map);

		// this.map = new HashMap<String, String>();
		// this.map.put("id", "woodColor");
		// this.map.put("title", "请选择木饰颜色");
		// this.map.put("content", this.woodColor);
		// this.allInputItems.add(this.map);
		this.map = new HashMap<String, String>();
		// this.map.put("id", "vin");
		// this.map.put("title", "请输入车架号");
		// this.map.put("content", this.vin);
		// this.allInputItems.add(this.map);

		this.map.put("id", "lungu");
		this.map.put("title", "请选择轮毂");
		this.map.put("content", this.lunGu);
		this.allInputItems.add(this.map);

		MyPublishCarAdapter adapter = new MyPublishCarAdapter(this,
				allInputItems);

		list1.setAdapter(adapter);
		//

		this.allInputItems = new ArrayList<Map<String, String>>();

		// this.map = new HashMap<String, String>();
		// this.map.put("id", "paiLiang");
		// this.map.put("title", "请选择排量");
		// this.map.put("content", this.paiLiang);
		// this.allInputItems.add(this.map);

		this.map = new HashMap<String, String>();
		this.map.put("id", "peizhi");
		this.map.put("title", "请选择配置");
		this.map.put("content", this.peizhi);
		this.allInputItems.add(this.map);

		adapter = new MyPublishCarAdapter(this, allInputItems);
		this.list2.setAdapter(adapter);

		this.allInputItems = new ArrayList<Map<String, String>>();
		this.map = new HashMap<String, String>();
		this.map.put("content", "");
		this.map.put("id", "photo");
		this.map.put("title", "请上传图片");

		this.allInputItems.add(map);
		// this.map = new HashMap<String, String>();
		// this.map.put("id", "beizhu");
		// this.map.put("title", "请输入备注内容");
		// this.map.put("content", this.beizhu);
		//
		// this.allInputItems.add(map);

		adapter = new MyPublishCarAdapter(this, allInputItems);
		this.list3.setAdapter(adapter);

	}

	// private String formalities = "";
	private String peizhi = "";
	// private String vin = "";
	private String mname = "";
	private String beizhu = "";

	private void showButton() {

		Button localButton = (Button) findViewById(R.id.leftButton);
		localButton.setVisibility(View.VISIBLE);

		localButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				// clearData();
				// mApp.setmVinName(null);
				finish();

			}
		});
	}

	private void clearData() {
		mApp.setCar(null);
		mApp.setmSeriesCar(null);
		mApp.setmEnteriorColor(null);
		mApp.setmInnerColor(null);
		// mApp.setmWoodColor(null);
		mApp.setmWheelHubName(null);
		mApp.setConfigurationOneIds(null);
		mApp.setConfigurationTwoIds(null);
		mApp.setConfigurationThreeIds(null);
		mApp.setConfigurationFourIds(null);
		mApp.getAllConfigurations().clear();
		// mApp.setmDisplacementName();
		mApp.setPriceInput("");
		mApp.getAllImgPaths().clear();
		// mApp.setEditor(false);
		mApp.setmQHDate(null);
		// mApp.getAllImgPaths().clear();
		mApp.setmCarStateValue(-1);
	}

	View.OnClickListener completeListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {

			System.out.println("complete----->");
			AsyncTask<String, String, String> t = new AsyncTask<String, String, String>() {

				@Override
				protected String doInBackground(String... params) {

					publishProgress("");
					return updateCarInfo();

				}

				@Override
				protected void onPostExecute(String result) {

					// System.out.println("result==="+result);
					hideLoading();
					if (result != null) {

						// System.out.println("res");
						if (result.indexOf("修改成功") >= 0) {

							showDialogFinish("修改成功", true);
						} else {
							Toast.makeText(getApplicationContext(),
									"修改失败，请稍候重试", Toast.LENGTH_SHORT).show();
						}
					}

					super.onPreExecute();
				}

				@Override
				protected void onProgressUpdate(String... values) {
					// showLoading("");

					super.onProgressUpdate(values);
				}

			};
			t.execute("");
		}
	};

	private class MyPublishCarAdapter extends BaseAdapter {

		private Context mContext;
		private List<Map<String, String>> mAllInputItems;

		public MyPublishCarAdapter(Context context,
				List<Map<String, String>> allInputItems) {

			this.mContext = context;
			this.mAllInputItems = allInputItems;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return this.mAllInputItems.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return this.mAllInputItems.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			// System.out.println("getView======>" + this);
			String type = mAllInputItems.get(position).get("id");

			if ((type.equals("typeAndStatus")) || (type.equals("model"))
					|| (type.equals("color")) || (type.equals("insideColor"))
					|| ("carState").equals(type)) {
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.base_list_items_simple, null);
				TextView textView = (TextView) convertView
						.findViewById(R.id.itemContent);
				textView.setHintTextColor(this.mContext.getResources()
						.getColorStateList(R.color.red_config));
				textView.setHint(this.mAllInputItems.get(position).get("title"));
				textView.setTextColor(this.mContext.getResources()
						.getColorStateList(R.color.font_blue_deep));
				textView.setText(this.mAllInputItems.get(position).get(
						"content"));

			}
			if ("photo".equals(type)) {
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.base_list_items_simple, null);
				TextView tx = (TextView) convertView
						.findViewById(R.id.itemContent);
				tx.setTextColor(this.mContext.getResources().getColorStateList(
						R.color.font_gray_light));
				tx.setText(mAllInputItems.get(position).get("title"));

			}

			if ("priceInput".equals(type)) {
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.publish_car_items_input_price_n, null);

				EditText localEditText3 = (EditText) convertView
						.findViewById(R.id.itemContent);
				localEditText3.setHint(this.mAllInputItems.get(position).get(
						"title"));

				// String price = mApp.getPriceInput();
				// if (price == null || price.equals("")) {
				// price = MyCarUpdatePublishActivity.this.price;
				// }
				String price = mApp.getmEditCarInfo().getPress();
				localEditText3.setText(price);

				// 给价格输入框设置监听事件

				localEditText3.addTextChangedListener(new TextWatcher() {

					@Override
					public void onTextChanged(CharSequence s, int start,
							int before, int count) {

						if (s.toString().trim().length() != 0) {

							mApp.getmEditCarInfo().setPress(s.toString());
						}

					}

					@Override
					public void beforeTextChanged(CharSequence s, int start,
							int count, int after) {
						// TODO Auto-generated method stub

					}

					@Override
					public void afterTextChanged(Editable s) {

						if (s.toString().trim().length() == 0) {

							Toast.makeText(getApplicationContext(), "请输入车的价格",
									Toast.LENGTH_SHORT).show();
						}

					}
				});

			}

			
			
			if ("vin".equals(type)) {
				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.publish_car_items_input_vin_n, null);

				EditText localEditText3 = (EditText) convertView
						.findViewById(R.id.itemContent);
				localEditText3.setHint(this.mAllInputItems.get(position).get(
						"title"));

				String vin = mApp.getmEditCarInfo().getVin();
				if (vin == null) {
					vin = "";
				}
				localEditText3.setText(vin);

				// 给价格输入框设置监听事件

				localEditText3.addTextChangedListener(new TextWatcher() {

					@Override
					public void onTextChanged(CharSequence s, int start,
							int before, int count) {

						if (s.toString().trim().length() != 0) {

							mApp.getmEditCarInfo().setVin(s.toString());
						}

					}

					@Override
					public void beforeTextChanged(CharSequence s, int start,
							int count, int after) {
						// TODO Auto-generated method stub

					}

					@Override
					public void afterTextChanged(Editable s) {
						// TODO Auto-generated method stub

					}
				});

			}
			
			
			if ("lungu".equals(type)) {

				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.base_list_items_simple, null);
				TextView textView = (TextView) convertView
						.findViewById(R.id.itemContent);
				textView.setHintTextColor(this.mContext.getResources()
						.getColorStateList(R.color.font_gray_light_2));
				textView.setHint(this.mAllInputItems.get(position).get("title"));
				textView.setTextColor(this.mContext.getResources()
						.getColorStateList(R.color.font_gray_light_2));
				textView.setText(this.mAllInputItems.get(position).get(
						"content"));

			}

			if ("peizhi".equals(type)) {

				convertView = LayoutInflater.from(mContext).inflate(
						R.layout.config_list_item, null);
				TextView textView = (TextView) convertView
						.findViewById(R.id.itemContent);
				textView.setHintTextColor(this.mContext.getResources()
						.getColorStateList(R.color.font_gray_light_2));
				textView.setHint(this.mAllInputItems.get(position).get("title"));
				textView.setTextColor(this.mContext.getResources()
						.getColorStateList(R.color.font_gray_light_2));
				textView.setText(this.mAllInputItems.get(position).get(
						"content"));
				convertView.setMinimumHeight(480);
			}

			convertView
					.setBackgroundResource(android.R.drawable.list_selector_background);
			return convertView;
		}

		@Override
		public boolean isEnabled(int position) {

			String str = this.mAllInputItems.get(position).get("id");

			if ((str.equals("typeAndStatus")) || (str.equals("model"))) {
				return false;
			} else {
				return super.isEnabled(position);
			}

		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

		EditCarInfo e = mApp.getmEditCarInfo();
		// Car c = app.getCar();
		// if (c != null) {
		// this.carType = c.getName();
		// } else {
		//
		// }
		//
		// c = app.getmSeriesCar();
		// if (c != null) {
		// this.mname = c.getName();
		// }

		// System.out.println("carType==="+this.carType+",,,mname==="+this.mname);
		// System.out.println(app + ",,onResme==");

		// if (app.getmEnteriorColor() != null) {
		// String exterior = app.getmEnteriorColor().get("name");
		// if (exterior != null) {
		// this.color = exterior;
		// }
		// }
		this.color = e.getWsname();
		// if (app.getmInnerColor() != null) {
		// String interior = app.getmInnerColor().get("name");
		// if (interior != null) {
		// this.insideColor = interior;
		// }
		// }
		this.insideColor = e.getNsname();
		// if (app.getmWoodColor() != null) {
		// String woodColor = app.getmWoodColor().get("name");
		// if (woodColor != null) {
		// this.woodColor = woodColor;
		// }
		// }
		this.woodColor = "";

		// if (app.getmWheelHubName() != null) {
		// String wheelHub = app.getmWheelHubName().get("name");
		//
		// if (wheelHub != null) {
		//
		// this.lunGu = wheelHub;
		// }
		// }
		this.lunGu = e.getLgname();

		// String vinName = app.getmDisplacementName();
		//
		// if (vinName != null) {
		// this.paiLiang = vinName;
		// }
		this.paiLiang = "";

		
		boolean flag = mApp.isEditor();
		System.out.println("flag===>"+flag+",,,"+mApp.getmCarStateValue());
		if (!flag) {
			this.carState = e.getXhorqh();

			//System.out.println("this.carState----"+this.carState);
			if (this.carState.indexOf("现货") >= 0) {
				mApp.setmCarStateValue(0);
			} else if (this.carState.indexOf("期货") >= 0) {
				this.carState = "期货-" + e.getQhtime() + "-到港";
				mApp.setmCarStateValue(1);
			}
		} else {
			int state = mApp.getmCarStateValue();
			String date = mApp.getmQHDate();
			// //"期货-"+car.getQhtime() + "-到港";
			if (state == 0) {
				this.carState = "现货";
			} else if (state == 1) {
				this.carState = "期货-" + date + "-到港";
			}
			// System.out.println("----isEditor---->");
			e.setXhorqh(this.carState);

			if (date != null) {
				e.setQhtime(date);
			}
			mApp.setmEditCarInfo(e);
		}

		boolean updateState = mApp.isUpdateConfigState();
		if (!updateState) {
			this.peizhi = e.getXppz();
		} else {
			editConfigInfo();
		}

		this.initViews();
	}

	@Override
	public void onItemClick(AdapterView<?> adapterView, View view,
			int position, long id) {

		String key = ((HashMap<String, String>) adapterView.getAdapter()
				.getItem(position)).get("id");

		EditCarInfo e = this.mApp.getmEditCarInfo();
		this.id = e.getXilieid();
		if ("color".equals(key)) {

			startNewActivity(ExteriorActivity.class, true, this.id);
		} else if ("insideColor".equals(key)) {

			startNewActivity(InteriorActivity.class, true, this.id);
		} else if ("woodColor".equals(key)) {

			startNewActivity(WoodColorActivity.class, true, this.id);
		} else if ("lungu".equals(key)) {

			startNewActivity(WheelHubActivity.class, true, this.id);
		} else if ("paiLiang".equals(key)) {

			startNewActivity(DisplacementActivity.class, true, this.id);
		} else if ("peizhi".equals(key)) {

			startNewActivity(ConfigurationActivity.class, true, this.id);
		} else if ("photo".equals(key)) {

			Intent intent = new Intent();
			intent.setClass(MyCarUpdatePublishActivity.this,
					PublishCarPickPhotoActivity.class);
			intent.putExtra("isEditor", true);
			startActivity(intent);
		} else if ("carState".equals(key)) {

			//
			// startNewActivity(SelectorCarStateActivity.class, false, "请选择车系列",
			// mApp.getmSeriesCar());

			Intent intent = new Intent();
			intent.setClass(MyCarUpdatePublishActivity.this,
					SelectorCarStateActivity.class);
			intent.putExtra("updateState", true);
			startActivity(intent);
		}

	}

	private void startNewActivity(Class classz, boolean isFlag, String id) {

		Intent intent = new Intent();
		intent.putExtra("cId", id);
		if (isFlag) {
			intent.putExtra("isEditor", true);
		}

		intent.setClass(this, classz);
		startActivity(intent);

	}

	/**
	 * 参数一：carId: 要编辑的车辆ID 参数二：seriesId: 系列ID 参数三：title: 标题（即外内饰简称,如“外黑内白”）
	 * 参数四：userId: 当前操作的用户ID 参数五：vin:车架号 参数六：configuration: 选配配置，多个配置以 ¤ 分割
	 * 格式如：运动套装¤后视摄像头¤加热方向盘 参数七：configurationIDs: 选配配置ID，多个配置id以,分割
	 * 格式如：,629,660,2061,2066 参数八：outerExteriorID : 外饰ID 参数九：innerColorID : 内饰ID
	 * 参数十：displacement : 排量 格式如： 3.0L 暂时无用，传空值即可 参数十一：seating: 座位数 格式如：
	 * 5暂时无用，传空值即可 参数十二：smallImg : 车辆图片 格式如：201401181006571972.jpg
	 * 当前年月日时分秒毫秒多个图片以小写的“；”分割(为了图片能够在pc端正常显示，需将图片大小设置为450X390，大小在100kb以下)
	 * 参数十三：woodColorID: 木饰ID 暂时无用，传空值即可 参数十四：wheelHubID: 轮毂ID 参数十五：press :价格（万）
	 * 参数十六：type: 期货还是现货(传入值为：“期货”，“现货”) 参数十七：typeTime: 期货到港时间（现货为空）只需要年月日
	 * 
	 * @return
	 */

	public String updateCarInfo() {

		EditCarInfo editCarInfo = mApp.getmEditCarInfo();
		// 封装参数

		HashMap<String, String> allParams = new HashMap<String, String>();

		allParams.put("carId", editCarInfo.getId());
		allParams.put("seriesId", editCarInfo.getXilieid());

		if (mApp.getmEnteriorColor() != null && mApp.getmInnerColor() != null) {
			String shortname1 = mApp.getmEnteriorColor().get("shortname");

			String shortname2 = mApp.getmInnerColor().get("shortname");
			editCarInfo.setName("外"+shortname1 + "内"+shortname2);
		}

		// if(shortname1!=null||shortname2!=null){
		//
		// editCarInfo.setName(shortname1+shortname2);
		// }else{
		//
		// }
		allParams.put("title", editCarInfo.getName());
		UserInfo u = (UserInfo) readObject("userInfo");
		allParams.put("userId", u.getUserId());
		allParams.put("vin", editCarInfo.getVin());

		progressConfiguration(allParams, editCarInfo);
		// allParams.put("configuration", editCarInfo.getXppz());// 配置信息
		// allParams.put("configurationIDs", editCarInfo.getDdid());
		allParams.put("outerExteriorID", editCarInfo.getWsid());// 外饰id
		allParams.put("innerColorID", editCarInfo.getNsid());// 内饰id
		allParams.put("displacement", "");
		allParams.put("seating", "");// 座位数

		progressImge(allParams, editCarInfo);
		// allParams.put("smallImg", parseImg(editCarInfo.getImg()));
		allParams.put("woodColorID", "");
		allParams.put("wheelHubID", editCarInfo.getLgid());
		allParams.put("press", editCarInfo.getPress());
		System.out.println("type=====" + editCarInfo.getXhorqh() + ",,date---"
				+ editCarInfo.getQhtime());
		allParams.put("type", editCarInfo.getXhorqh());
		allParams.put("typeTime", editCarInfo.getQhtime());

		NetworkProgressUtils utils = NetworkProgressUtils.getInstance();
		Object o = utils.getWebservicesByData(
				ConstantUtils.NAME_SPACE,
				ConstantUtils.ALL_METHROD_NAME.get(48),
				ConstantUtils.NAME_SPACE
						+ ConstantUtils.ALL_METHROD_NAME.get(48),
				ConstantUtils.UPDATE_CARS_BY_CAR_ID_URL, allParams);

		// System.out.println(o.toString());
		return o.toString();
	}

	private String parseImg(String img) {

		if (img != null) {
			String splits[] = img.split(";");

			StringBuffer sb = new StringBuffer();

			int index = splits.length;

			for (int i = 0; i < index; i++) {

				String tmp = splits[i];
				tmp = tmp.substring(tmp.lastIndexOf("/") + 1);

				sb.append(tmp).append(";");

			}

			System.out.println("sb--" + sb.toString());
			return sb.toString();
		}

		return "";
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		clearData();
	}

	private Handler mHandler = new Handler() {

		public void handleMessage(android.os.Message msg) {

			Toast.makeText(MyCarUpdatePublishActivity.this,
					"没有确定车源类型或车源系列，不能发布车源", Toast.LENGTH_SHORT).show();
		}
	};

	private void progressConfiguration(HashMap<String, String> allParams,
			EditCarInfo editCarInfo) {

		long[] checksOne = mApp.getConfigurationOneIds();
		long[] checksTwo = mApp.getConfigurationTwoIds();
		long[] checksThree = mApp.getConfigurationThreeIds();
		long[] checksFour = mApp.getConfigurationFourIds();
		HashMap<String, ArrayList<BaseColorInfo>> allItems = mApp
				.getAllConfigurations();
		if ((checksOne == null && checksTwo == null && checksThree == null && checksFour == null)
				|| (allItems == null || allItems.size() == 0)) {
			allParams.put("configuration", editCarInfo.getXppz());// 配置信息
			allParams.put("configurationIDs", editCarInfo.getDdid());
			// return null;
			return;
		}

		ArrayList<BaseColorInfo> bc1 = allItems.get(ConfigurationActivity.KEY1);
		ArrayList<BaseColorInfo> bc2 = allItems.get(ConfigurationActivity.KEY2);
		ArrayList<BaseColorInfo> bc3 = allItems.get(ConfigurationActivity.KEY3);
		ArrayList<BaseColorInfo> bc4 = allItems.get(ConfigurationActivity.KEY4);
		// ArrayList<String> allItems1 = new ArrayList<String>();
		// ArrayList<String> allItems2 = new ArrayList<String>();
		StringBuffer sb1 = new StringBuffer();
		StringBuffer configIdsOne = new StringBuffer();
		StringBuffer configIdsTwo = new StringBuffer();
		StringBuffer configIdsThree = new StringBuffer();
		StringBuffer configIdsFour = new StringBuffer();

		for (int i = 0; i < checksOne.length; i++) {

			BaseColorInfo b = bc1.get((int) checksOne[i]);
			// allItems1.add(b.getDdname());
			sb1.append(b.getDdname()).append("¤");

			configIdsOne.append(",").append(b.getId());

		}
		configIdsOne.append(",");
		StringBuffer sb2 = new StringBuffer();
		for (int i = 0; i < checksTwo.length; i++) {

			BaseColorInfo b = bc2.get((int) checksTwo[i]);
			sb2.append(b.getDdname());

			configIdsTwo.append(b.getId());
			if ((i == checksTwo.length - 1)) {
				sb2.append("");
				configIdsTwo.append("");
			} else {
				sb2.append("¤");
				configIdsTwo.append(",");
			}

			// allItems2.add(b.getDdname());

		}

		StringBuffer sb3 = new StringBuffer();
		for (int i = 0; i < checksThree.length; i++) {

			BaseColorInfo b = bc3.get((int) checksThree[i]);
			sb3.append("¤").append(b.getDdname());
			configIdsThree.append(",").append(b.getId());
		}

		StringBuffer sb4 = new StringBuffer();

		for (int i = 0; i < checksFour.length; i++) {

			BaseColorInfo b = bc4.get((int) checksFour[i]);
			sb4.append("¤").append(b.getDdname());
			configIdsFour.append(",").append(b.getId());
		}
		// configIdsFour.append(",");
		configIdsThree.append(configIdsFour);
		configIdsTwo.append(configIdsThree);
		sb3.append(sb4);
		sb2.append(sb3);
		sb1.append(sb2);
		configIdsOne.append(configIdsTwo);
		allParams.put("configuration", sb1.toString());// 配置信息
		// System.out.println("configuration=" + sb1.toString());
		allParams.put("configurationIDs", configIdsOne.toString());
		System.out.println(configIdsOne.toString());
	}

	private void progressImge(HashMap<String, String> allParams,
			EditCarInfo editCarInfo) {

		HashMap<String, String> allImgs = mApp.getAllImgPaths();
		if (allImgs == null || allImgs.size() == 0) {
			allParams.put("smallImg", parseImg(editCarInfo.getImg()));
			return;
		}
		ArrayList<String> allImgNames = mApp.getAllImgNames();
		System.out.println("update===>" + allImgNames + "," + allImgs);
		// if (allImgs != null && allImgs.size() != 0) {
		// // for (int i = 0; i < allImgs.size(); i++) {
		// // String name = allImgs.get("" + (i + 1));
		// // String fileName = name.substring(name.lastIndexOf("/") + 1,
		// // name.length());
		// // allImgNames.add(fileName);
		// // new UploadImageTask(name, fileName).execute("");
		// //
		// // }
		//
		//
		// }

		Set s = allImgs.entrySet();
		Iterator<Map.Entry<String, String>> iterator = s.iterator();

		while (iterator.hasNext()) {
			Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator
					.next();

			String name = entry.getValue();

			String fileName = name.substring(name.lastIndexOf("/") + 1,
					name.length());
			allImgNames.add(fileName);
			new UploadImageTask(name, fileName).execute("");

		}
		StringBuffer imgSplits = new StringBuffer();
		for (int i = 0; i < allImgNames.size(); i++) {
			imgSplits.append(allImgNames.get(i)).append(";");

		}
		System.out.println("uploadImage-------@@@" + imgSplits.toString());
		allParams.put("smallImg", imgSplits.toString());

	}

	private void editConfigInfo() {

		HashMap<String, ArrayList<BaseColorInfo>> allItems = mApp
				.getAllConfigurations();
		// System.out.println("-----configuration-->");

		if (allItems != null && allItems.size() > 0) {

			boolean isSelect = mApp.isSelect();
			if (isSelect) {

				ArrayList<BaseColorInfo> bc1 = allItems
						.get(ConfigurationActivity.KEY1);
				ArrayList<BaseColorInfo> bc2 = allItems
						.get(ConfigurationActivity.KEY2);
				ArrayList<BaseColorInfo> bc3 = allItems
						.get(ConfigurationActivity.KEY3);
				ArrayList<BaseColorInfo> bc4 = allItems
						.get(ConfigurationActivity.KEY4);
				// ArrayList<String> allItems1 = new ArrayList<String>();
				// ArrayList<String> allItems2 = new ArrayList<String>();
				StringBuffer sb1 = new StringBuffer();
				StringBuffer configIdsOne = new StringBuffer();
				StringBuffer configIdsTwo = new StringBuffer();
				StringBuffer configIdsThree = new StringBuffer();
				StringBuffer configIdsFour = new StringBuffer();
				long[] checksOne = mApp.getConfigurationOneIds();
				long[] checksTwo = mApp.getConfigurationTwoIds();
				long[] checksThree = mApp.getConfigurationThreeIds();
				long[] checksFour = mApp.getConfigurationFourIds();

				for (int i = 0; i < checksOne.length; i++) {

					BaseColorInfo b = bc1.get((int) checksOne[i]);
					// allItems1.add(b.getDdname());
					sb1.append(b.getDdname()).append("¤");

					configIdsOne.append(",").append(b.getId());

				}
				configIdsOne.append(",");
				StringBuffer sb2 = new StringBuffer();
				for (int i = 0; i < checksTwo.length; i++) {

					BaseColorInfo b = bc2.get((int) checksTwo[i]);
					sb2.append(b.getDdname());

					configIdsTwo.append(b.getId());
					if ((i == checksTwo.length - 1)) {
						sb2.append("");
						configIdsTwo.append("");
					} else {
						sb2.append("¤");
						configIdsTwo.append(",");
					}

					// allItems2.add(b.getDdname());

				}

				StringBuffer sb3 = new StringBuffer();
				for (int i = 0; i < checksThree.length; i++) {

					BaseColorInfo b = bc3.get((int) checksThree[i]);
					sb3.append("¤").append(b.getDdname());
					configIdsThree.append(",").append(b.getId());
				}

				StringBuffer sb4 = new StringBuffer();

				for (int i = 0; i < checksFour.length; i++) {

					BaseColorInfo b = bc4.get((int) checksFour[i]);
					sb4.append("¤").append(b.getDdname());
					configIdsFour.append(",").append(b.getId());
				}
				// configIdsFour.append(",");
				configIdsThree.append(configIdsFour);
				configIdsTwo.append(configIdsThree);
				sb3.append(sb4);
				sb2.append(sb3);
				sb1.append(sb2);
				configIdsOne.append(configIdsTwo);

				this.peizhi = sb1.toString();
				// allParams.put("configuration", sb1.toString());// 配置信息
				// System.out.println("configuration=" + sb1.toString());
				// allParams.put("configurationIDs", configIdsOne.toString());
			} else {

				this.peizhi = "";
			}
		}
	}
}
